package com.cxyd.modules.wcs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cxyd.common.constant.WcsConstants;
import com.cxyd.common.service.impl.CrudServiceImpl;
import com.cxyd.common.utils.ConvertUtils;
import com.cxyd.modules.log.service.SysLogWorkService;
import com.cxyd.modules.wcs.dao.StockDao;
import com.cxyd.modules.wcs.dto.StnMappingDTO;
import com.cxyd.modules.wcs.dto.StockDTO;
import com.cxyd.modules.wcs.entity.StnMappingEntity;
import com.cxyd.modules.wcs.entity.StockEntity;
import com.cxyd.modules.wcs.service.StockService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 库存信息
 *
 * @author g_Cycle gengruyi01@163.com
 * @since 1.0.0 2023-04-27
 */
@Service
public class StockServiceImpl extends CrudServiceImpl<StockDao, StockEntity, StockDTO> implements StockService {
    @Resource
    private StockDao stockDao;
    @Resource
    private SysLogWorkService logWorkService;

    @Override
    public QueryWrapper<StockEntity> getWrapper(Map<String, Object> params) {
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void stockDisables(List<Long> ids, Integer status) {
        for (Long stockId : ids) {
            StockEntity stockEntity = baseDao.selectById(stockId);
            if (ObjectUtils.isEmpty(stockEntity)) {
                throw new RuntimeException("库存不存在");
            }
            //前端传入status 0就是禁用货位，传入 1就是解禁货位
            int activeNew;
            if (status == 0) {
                activeNew = 1;
            } else {
                activeNew = 0;
            }
            stockEntity.setLockSt(activeNew);
            baseDao.updateById(stockEntity);
        }
    }

}